#include <iostream>
#include <boost/smart_ptr.hpp>
#include "observer.h"

//具体博客类
class BlogCSDN : public Blog
{
  public:
    BlogCSDN(std::string name): m_name(name) {}
    ~BlogCSDN() {}
    void SetStatus(std::string s) { m_status = "CSDN通知 : " + m_name + s; } //具体设置状态信息
    std::string GetStatus() { return m_status; }
  
  private:
    std::string m_name; //博主名称
};

//具体观察者
class ObserverBlog : public Observer   
{
  public: 
    ObserverBlog(std::string name, Blog *blog): m_name(name), m_blog(blog) {}
    ~ObserverBlog() {}
    void Update()  //获得更新状态
    {
      std::string status = m_blog->GetStatus();
      std::cout << m_name << " ------- " << status << std::endl;
    }

  private:
    std::string m_name;	//观察者名称
    Blog	*m_blog;   //观察的博客，当然以链表形式更好，就可以观察多个博客
};


//测试案例
int main(void)
{
  Blog* blog = new BlogCSDN("wuzhekai1985");
  Observer* observer1 = new ObserverBlog("tutupig1", blog);
  Observer* observer2 = new ObserverBlog("tutupig2", blog);
  blog->Attach(observer1);
  blog->Attach(observer2);
  blog->SetStatus("发表设计模式C++实现（15）——观察者模式");
  blog->Notify();

  delete blog;
  delete observer1;
  return (0);
}

